package com.jtny.nytb.equipment.vo.dataparam;

import cn.hutool.core.util.StrUtil;
import com.jtny.nytb.config.datafactor.dto.ConfigDataParamManagementDTO;
import com.jtny.nytb.equipment.dto.dataparam.DataParamTempDTO;
import com.jtny.nytb.valid.annotation.ValueValid;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author 智慧能源中心 - 伍天宇
 * @package com.jtny.nytb.equipment.vo.dataparam
 * @fileName DataParamBaseVO.java
 * @createTime 2023年10月06日 22:33
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "DataParamBaseVO", description = "数据参量基础数据")
public class DataParamBaseVO implements Serializable {
    @ApiModelProperty("主键id，自增长")
    protected Long id;

    /**
     * 参量编号
     */
    @ApiModelProperty("参量编号")
    private String code;

    /**
     * 参量名称
     */
    @ApiModelProperty("参量名称")
    private String name;

    /**
     * 参量别名
     */
    @ApiModelProperty("参量别名")
    private String alias;

    /**
     * 参量状态，0表示正常，1表示禁用，9表示已删除
     */
    @ApiModelProperty("参量状态，0表示正常，1表示禁用，9表示已删除")
    private Integer status;

    /**
     * 数据上报标识
     */
    @ApiModelProperty(value = "数据上报标识", required = true)
    @NotBlank(message = "数据上报标识不能为空")
    private String reportIdentifier;

    /**
     * 统一参量标识
     */
    @ApiModelProperty(value = "统一参量标识", required = true)
    private String unifiedIdentifier;

    /**
     * 统一参量标识名称
     */
    @ApiModelProperty(value = "统一参量标识名称", required = true)
    private String unifiedIdentifierName;

    /**
     * 参量来源(1设备自动采集 2系统计算 3常量 4手动填报)
     */
    @ApiModelProperty(value = "参量来源(1设备自动采集 2系统计算 3常量 4手动填报)", required = true)
    @ValueValid(intValues = {1, 2, 3, 4}, message = "参量来源不能为空", ignoreEmpty = false)
    private Integer source;


//    /**
//     * 计量长度id
//     */
//    @ApiModelProperty(value = "计量长度单位Id", required = true)
//    @NotBlank(message = "计量长度不能为空")
//    private String measurementUnitId;

    /**
     * 计量单位名字
     */
    @ApiModelProperty(value = "计量单位名字", required = true)
    @NotBlank(message = "计量单位不能为空")
    private String measurementUnit;

    /**
     * 小数点位
     */
    @ApiModelProperty(value = "小数点位", required = true)
    @NotNull(message = "小数点位不能为空")
    private Integer digit;


    /**
     * 实时量/累计量(1:实时量;2:累计量)
     */
    @ApiModelProperty(value = "实时量/累计量(0:实时量;1:累计量)", required = true)
    @ValueValid(intValues = {1, 2}, message = "实时量/累计量不能为空", ignoreEmpty = false)
    private Integer dataType;

    /**
     * 默认图表
     */
    @ApiModelProperty(value = "默认图表: '1': '流向图 ,'2': '柱状图','3': '折线图','4': '饼图'", required = true)
    @ValueValid(intValues = {1, 2, 3, 4}, message = "默认图表不能为空", ignoreEmpty = false)
    private Integer chart;

    /**
     * 描述
     */
    @ApiModelProperty("描述")
    private String paramDescribe;

    public DataParamBaseVO(ConfigDataParamManagementDTO configDataParamManagementDTO) {
        this.id = configDataParamManagementDTO.getId();
        this.code = configDataParamManagementDTO.getCode();
        this.name = configDataParamManagementDTO.getName();
        this.alias = configDataParamManagementDTO.getAlias();
        this.reportIdentifier = configDataParamManagementDTO.getReportIdentifier();
        this.unifiedIdentifier = configDataParamManagementDTO.getUnifiedIdentifier();
        this.unifiedIdentifierName = configDataParamManagementDTO.getUnifiedIdentifierName();
        this.source = configDataParamManagementDTO.getSource();
        this.measurementUnit = configDataParamManagementDTO.getMeasurementUnit();
        this.digit = configDataParamManagementDTO.getDigit();
        this.dataType = configDataParamManagementDTO.getDataType();
        this.chart = configDataParamManagementDTO.getChart();
        this.paramDescribe = configDataParamManagementDTO.getParamDescribe();
    }

    public DataParamTempDTO buildDTO() {
        DataParamTempDTO result = new DataParamTempDTO();
        result.setId(id);
        result.setCode(code);
        result.setName(unifiedIdentifierName);
        result.setAlias(alias);
        result.setStatus(status);
        result.setReportIdentifier(reportIdentifier);
        result.setUnifiedIdentifier(unifiedIdentifier);
        result.setUnifiedIdentifierName(unifiedIdentifierName);
        result.setSource(source);
        result.setMeasurementUnit(measurementUnit);
        result.setDigit(digit);
        result.setDataType(dataType);
        result.setChart(chart);
        result.setParamDescribe(paramDescribe);
        return result;
    }

    public DataParamTempDTO buildDTO2() {
        DataParamTempDTO result = new DataParamTempDTO();
        result.setId(id);
        result.setCode(code);
        result.setName(name);
        result.setAlias(alias);
        result.setStatus(status);
        result.setReportIdentifier(reportIdentifier);
        result.setUnifiedIdentifier(unifiedIdentifier);
        result.setUnifiedIdentifierName(unifiedIdentifierName);
        result.setSource(source);
        result.setMeasurementUnit(measurementUnit);
        result.setDigit(digit);
        result.setDataType(dataType);
        result.setChart(chart);
        result.setParamDescribe(paramDescribe);
        return result;
    }

    public ConfigDataParamManagementDTO buildConfigDataParamManagementDTO() {
        ConfigDataParamManagementDTO result = new ConfigDataParamManagementDTO();
        result.setId(id);
        result.setCode(code);
        result.setName(unifiedIdentifierName);
        result.setAlias(alias);
        result.setReportIdentifier(reportIdentifier);
        result.setUnifiedIdentifier(unifiedIdentifier);
        result.setUnifiedIdentifierName(unifiedIdentifierName);
        result.setSource(source);
        result.setMeasurementUnit(measurementUnit);
        result.setDigit(digit);
        result.setDataType(dataType);
        result.setChart(chart);
        result.setParamDescribe(paramDescribe);
        return result;
    }

    protected ConfigDataParamManagementDTO buildDataParamDTO() {
        ConfigDataParamManagementDTO result = new ConfigDataParamManagementDTO();
        result.setId(id);
        result.setCode(code);
        if (StrUtil.isBlank(name)) {
            result.setName(unifiedIdentifierName);
        } else {
            result.setName(name);
        }
        result.setAlias(alias);
        result.setReportIdentifier(reportIdentifier);
        result.setUnifiedIdentifier(unifiedIdentifier);
        result.setUnifiedIdentifierName(unifiedIdentifierName);
        result.setSource(source);
        result.setMeasurementUnit(measurementUnit);
        result.setDigit(digit);
        result.setDataType(dataType);
        result.setChart(chart);
        result.setParamDescribe(paramDescribe);
        return result;
    }

    public DataParamBaseVO(DataParamTempDTO dataParamTempDTO) {
        this.id = dataParamTempDTO.getId();
        this.code = dataParamTempDTO.getCode();
        this.name = dataParamTempDTO.getName();
        this.alias = dataParamTempDTO.getAlias();
        this.status = dataParamTempDTO.getStatus();
        this.reportIdentifier = dataParamTempDTO.getReportIdentifier();
        this.unifiedIdentifier = dataParamTempDTO.getUnifiedIdentifier();
        this.unifiedIdentifierName = dataParamTempDTO.getUnifiedIdentifierName();
        this.source = dataParamTempDTO.getSource();
        this.measurementUnit = dataParamTempDTO.getMeasurementUnit();
        this.digit = dataParamTempDTO.getDigit();
        this.dataType = dataParamTempDTO.getDataType();
        this.chart = dataParamTempDTO.getChart();
        this.paramDescribe = dataParamTempDTO.getParamDescribe();
    }

}
